<?php

use Illuminate\Database\Seeder;

class UserSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        //如果seed种子数据比较少的话,可以通过调用相应模型的create方法来创建种子数据
//        \App\User::create([
//           'name'=>'daoheng',
//           'password'=>'nihao139',
//            'email' => 'nihao@qq.com',
//        ]);
        //但是当要生成的faker数据比较多的时候可以使用模型工厂factory
         $data = factory(\App\User::class,20)->create();
         $data[0]['name'] = 'daoheng';
         $data[0]['email'] = 'nihao@com';
        $data[0] -> save();
        $data[1]['name'] = 'nihao';
        $data[1]['email'] = 'houge198841@qq.com';
        $data[1] ->save();
         //用户创建完成后,可以给用户分配角色
        $data[0]->assignRole('daoheng');
        $data[1]->assignRole('edit');
    }
}
